# -*- coding: utf-8 -*-
# @version        : 1.0
# @Create Time    : 2024/06/19 15:47
# @File           : settings.py
# @IDE            : PyCharm
# @desc           : 主配置文件

from pathlib import Path
from dynaconf import Dynaconf

#####################################################
#                     基础配置                       #
#####################################################
"""
系统版本
"""
VERSION = "1.0.0"


#####################################################
#                     目录配置                       #
#####################################################
"""项目根目录"""
BASE_DIR = Path(__file__).parent.parent

"""
挂载静态目录，并添加路由访问，此路由不会在接口文档中显示
STATIC_ENABLE：是否启用静态目录访问
STATIC_URL：路由访问
STATIC_ROOT：静态文件目录绝对路径
官方文档：https://fastapi.tiangolo.com/tutorial/static-files/
"""
STATIC_ENABLE = True
STATIC_URL = "/media"
STATIC_DIR = "static"
STATIC_ROOT = Path(BASE_DIR) / STATIC_DIR

#####################################################
#                   引入CONFIG配置                    #
#####################################################
CONFIG_DIR = BASE_DIR / "application" / "config"
CONFIG = Dynaconf(
    envvar_prefix="DC",
    settings_files=[i for i in CONFIG_DIR.iterdir()]
)

DEBUG = CONFIG.DEBUG or False
OAUTH_ENABLE = CONFIG.OAUTH_ENABLE or False
COOKIE_KEY = CONFIG.COOKIE_KEY or "xxl_sso_sessionid"

SQLALCHEMY_DATABASE_URL = CONFIG.SQLALCHEMY_DATABASE_URL or "mysql+asyncmy://root:123456@localhost:3306/dispatch_check"

MONGO_DB_ENABLE= CONFIG.MONGO_DB_ENABLE
MONGO_DB_URL = CONFIG.MONGO_DB_URL or "mongodb://dc:123456@localhost:27017/?authSource=dispatch_check"

REQUEST_LOG_RECORD = CONFIG.REQUEST_LOG_RECORD or False
OPERATION_LOG_RECORD = CONFIG.OPERATION_LOG_RECORD or False
OPERATION_RECORD_METHOD = CONFIG.OPERATION_RECORD_METHOD or []

IGNORE_OPERATION_FUNCTION = CONFIG.IGNORE_OPERATION_FUNCTION or []

APICALL_LOG_RECORD = CONFIG.APICALL_LOG_RECORD or False
APICALL_RECORD_METHOD = CONFIG.APICALL_RECORD_METHOD or []
IGNORE_APICALL_FUNCTION = CONFIG.IGNORE_APICALL_FUNCTION or []


"""
全局事件配置
"""
EVENTS = [
    "core.event.connect_mongo" if MONGO_DB_ENABLE else None,
    "core.event.check_config",
    # "core.event.mount_schedule_task"
]

"""
中间件配置
"""
MIDDLEWARES = [
    "core.middleware.register_request_log_middleware" if REQUEST_LOG_RECORD else None,
    "core.middleware.register_operation_record_middleware" if OPERATION_LOG_RECORD and MONGO_DB_ENABLE else None
]


